package top.szhome.develop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.szhome.framework.starter.db.support.SimpleServiceImpl;
import top.szhome.develop.convert.TemplateConverter;
import top.szhome.develop.dto.TemplateDTO;
import top.szhome.develop.entity.Template;
import top.szhome.develop.mapper.TemplateMapper;
import top.szhome.develop.service.TemplateService;
import top.szhome.develop.vo.TemplateVO;

import java.util.List;

/**
 * 模版服务实现
 *
 * @author 唐加利
 * @date 2023/08/21
 **/
@AllArgsConstructor
@Service
@Slf4j
public class TemplateServiceImpl extends SimpleServiceImpl<TemplateMapper, TemplateConverter, TemplateDTO, Template, TemplateVO> implements TemplateService {

    @Override
    public List<Template> getTemplates(Long templateSchemaId) {
        LambdaQueryWrapper<Template> query = Wrappers.lambdaQuery(Template.class).eq(Template::getTemplateSchemaId, templateSchemaId);
        return getBaseMapper().selectList(query);
    }

    @Override
    public Template getTemplate(Long templateSchemaId, String code) {
        LambdaQueryWrapper<Template> query = Wrappers.lambdaQuery(Template.class)
                .eq(Template::getTemplateSchemaId, templateSchemaId)
                .eq(Template::getCode, code);
        return getBaseMapper().selectOne(query);
    }
}
